`include "ctrl_encode_def.v"
`include "ctrl_encode_def.v"
module NPC(Zero, Reg, PC, NPCOp, IMM, NPC, PCPLUS4);  // next pc module

	input              Zero;
	input      [31:0]   Reg;
	input      [31:0]    PC;      // pc
	input       [1:0] NPCOp;      // next pc operation
	input      [25:0]   IMM;      // immediate
	output reg [31:0]   NPC;      // next pc
	
	output wire [31:0] PCPLUS4;
	
	assign PCPLUS4 = PC + 4;
	
	always @(*) begin
		case (NPCOp)
			`NPC_PLUS4:  NPC = PCPLUS4;
			`NPC_BRANCH: 
			begin
				if (Zero == 1)
					NPC = PCPLUS4 + {{14{IMM[15]}}, IMM[15:0], 2'b00};
				else
					NPC = PCPLUS4;
			end
			`NPC_JUMP:   NPC = {PCPLUS4[31:28], IMM[25:0], 2'b00};
			`NPC_JR:     NPC = Reg;
			default:     NPC = PCPLUS4;
		endcase
	end
		
endmodule